package org.example.ssh

import net.schmizz.sshj.SSHClient
import org.example.ssh.base.SSH
import org.example.ssh.base.executeCmdPrint

/*
/nginx/
├── conf.d/               # 自定义 server 配置
│   └── nexus.conf
├── nginx.conf            # 主配置文件
├── html/                 # 静态页面（可选）
│   └── index.html
        static/
    │   ├── main.js
    │   └── app.css
        favicon.ico
├── logs/                 # 日志目录
│   ├── access.log
│   └── error.log
├── cache/                # 缓存目录（可选）
└── ssl/                  # SSL 证书
    ├── nexus.crt
    └── nexus.key

/your-path/html/
├── index.html
├── static/
│   ├── main.js
│   └── app.css
└── favicon.ico

* */
suspend fun main() {
//    DeployNginx().deploy(SSH.getSsh("dev"))
}
class DeployNginx {
    lateinit var ssh: SSHClient
    val ngDir = "/home/ng-web"

    suspend fun deploy(ssh: SSHClient) {
//        executeCmdPrint(ssh, "docker pull nginx:1.28")
//        executeCmdPrint(ssh, "docker images")

//        return
        val sftp = ssh.newSFTPClient()
//        uploadDirectoryRecursive(sftp, "./配置/nginx/html", ngDir)
//        uploadDirectoryRecursive(sftp, "./配置/nginx/ssl", ngDir)
//        println("上传成功")
//        sftp.put("./配置/nginx/nginx.conf", "$ngDir/nginx.conf")
        sftp.put("./配置/nginx/nginx-compose-01.yml", "$ngDir/nginx-compose-01.yml")
//        println("上传成功")

        executeCmdPrint(ssh, "cd $ngDir && docker-compose -f nginx-compose-01.yml up -d")

//        executeCmdPrint(ssh, "cd $ngDir && docker-compose -f nginx-compose-01.yml down")

        executeCmdPrint(ssh, "docker exec v2board-app sh -c 'nginx -s reload'")
    }
}










